

package com.hexinfo.dmpro.script.pack.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.script.pack.entity.ScriptPackScanListEntity;
import com.hexinfo.dmpro.script.pack.service.IScriptPackScanListService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 脚本打包扫描清单
 *
 * @author Wang zhihao
 * @date 2023-09-13 18:05:43
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/scriptPack/list")
public class ScriptPackScanListController {

    private final IScriptPackScanListService scriptPackScanListService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param scriptPackScanList 脚本打包扫描清单
     * WrapperEnhancer.like(scriptPackScanList); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping(value = "/page")
    public ResponseEntity<Object> getScriptPackScanListPage(Page page, ScriptPackScanListEntity scriptPackScanList) {
        return new ResponseEntity<>(scriptPackScanListService.queryList(page,scriptPackScanList), HttpStatus.OK);
    }

    /**
     * 根据任务ID查询
     * @param taskId 任务ID
     * @return
     */
    @ApiOperation(value = "根据任务ID查询", notes = "根据任务ID查询")
    @GetMapping(value = "/listByTaskId/{taskId}")
    public ResponseEntity<Object> getListByTaskId(@PathVariable("taskId" ) String taskId) {
        return new ResponseEntity<>(scriptPackScanListService.getListByTaskId(taskId), HttpStatus.OK);
    }

    /**
     * 通过id查询脚本打包扫描清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(scriptPackScanListService.getById(id));
    }

    /**
     * 通过taskId获取检查结果为失败的文件
     * @param taskId
     * @return R
     */
    @ApiOperation(value = "通过taskId获取检查结果为失败的文件", notes = "通过taskId获取检查结果为失败的文件")
    @GetMapping("/allResult/{taskId}" )
    public ResponseEntity<Object> getFailResultByTaskId(@PathVariable String taskId) {
        return ResponseEntity.ok(scriptPackScanListService.getFailFileByTaskId(taskId));
    }

    /**
     * 新增脚本打包扫描清单
     * @param scriptPackScanList 脚本打包扫描清单
     * @return R
     */
    @ApiOperation(value = "新增脚本打包扫描清单", notes = "新增脚本打包扫描清单")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody ScriptPackScanListEntity scriptPackScanList) {
        return new ResponseEntity<>(scriptPackScanListService.save(scriptPackScanList), HttpStatus.OK);

    }

    /**
     * 修改脚本打包扫描清单
     * @param scriptPackScanList 脚本打包扫描清单
     * @return R
     */
    @ApiOperation(value = "修改脚本打包扫描清单", notes = "修改脚本打包扫描清单")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody ScriptPackScanListEntity scriptPackScanList) {
        return ResponseEntity.ok(scriptPackScanListService.updateById(scriptPackScanList));
    }

    /**
     * 通过id删除脚本打包扫描清单
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除脚本打包扫描清单", notes = "通过id删除脚本打包扫描清单")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(scriptPackScanListService.removeById(id));
    }

    @ApiOperation(value = "通过id一键忽略告警", notes = "通过id一键忽略告警")
    @PutMapping("/{id}" )
    public ResponseEntity<Object> batchIgnoreById(@PathVariable("id" ) String id) {
        scriptPackScanListService.batchIgnoreById(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}

